//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __CACTIVETIMER_H__
#define __CACTIVETIMER_H__

#include <elapi.h>

_ELASTOS_NAMESPACE_USING

enum ActiveTimerEvent {
    ActiveTimerEvent_Start  = 0x10,
    ActiveTimerEvent_Stop,
    ActiveTimerEvent_Quit,
};

#define CTIMER_MINIMUM_PERIOD   30  // in milliseconds

class CActiveTimer : public IActiveTimer
{
public:
    CARAPI_(PInterface) Probe(REIID riid);
    CARAPI_(UInt32) AddRef();
    CARAPI_(UInt32) Release();
    CARAPI Aggregate(AggregateType type, PInterface pObj);
    CARAPI GetDomain(PInterface *ppObj);

    CActiveTimer(
        /* [in] */ Millisecond32 interval,
        /* [in] */ PVoid pEntry,
        /* [in] */ PVoid pUserData);

    virtual ~CActiveTimer();

    CARAPI Start();

    CARAPI Stop();

    CARAPI SetInterval(
        /* [in] */ Millisecond32 interval);

    CARAPI GetInterval(
        /* [out] */ Millisecond32 * pInterval);

    CARAPI SetPriority(
        /* [in] */ ThreadPriority priority);

    CARAPI GetPriority(
        /* [out] */ ThreadPriority * pPriority);

public:
    Interlocked m_cRef;
    Int32       m_nInterval;
    EventHandler    m_timerRoutine;
    IThread   * m_pTimerThread;
    IEvent    * m_pEvent;
};

#endif // __CACTIVETIMER_H__
